<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>现代化表单设计</title>
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --success-color: #4cc9f0;
            --error-color: #f72585;
            --text-color: #2b2d42;
            --light-bg: #f8f9fa;
            --border-radius: 8px;
            --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background-color: #f5f5f5;
            color: var(--text-color);
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            width: 100%;
            max-width: 800px;
            background-color: white;
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            overflow: hidden;
        }

        .form-header {
            background-color: var(--primary-color);
            color: white;
            padding: 20px;
            text-align: center;
        }

        .form-header h1 {
            font-size: 24px;
            margin-bottom: 10px;
        }

        .form-header p {
            opacity: 0.9;
        }

        .form-content {
            padding: 30px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
        }

        input, select {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: var(--border-radius);
            font-size: 16px;
            transition: border-color 0.3s;
        }

        input:focus, select:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
        }

        input[type="date"], input[type="month"], input[type="time"], input[type="week"] {
            appearance: none;
        }

        .radio-group {
            display: flex;
            gap: 20px;
        }

        .radio-option {
            display: flex;
            align-items: center;
            cursor: pointer;
        }

        .radio-option input {
            width: auto;
            margin-right: 8px;
        }

        .range-container {
            display: flex;
            flex-direction: column;
        }

        .range-value {
            text-align: center;
            font-weight: bold;
            margin-top: 10px;
            color: var(--primary-color);
        }

        .color-preview {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            display: inline-block;
            margin-left: 10px;
            border: 1px solid #ddd;
        }

        .btn-group {
            display: flex;
            gap: 15px;
            margin-top: 30px;
        }

        .btn {
            padding: 12px 24px;
            border: none;
            border-radius: var(--border-radius);
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s;
            flex: 1;
        }

        .btn-primary {
            background-color: var(--primary-color);
            color: white;
        }

        .btn-primary:hover {
            background-color: var(--secondary-color);
        }

        .btn-secondary {
            background-color: #e9ecef;
            color: var(--text-color);
        }

        .btn-secondary:hover {
            background-color: #dee2e6;
        }

        .error-message {
            color: var(--error-color);
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }

        .input-with-feedback {
            position: relative;
        }

        .feedback-text {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 14px;
            color: #6c757d;
        }

        @media (max-width: 768px) {
            .container {
                border-radius: 0;
            }

            .form-content {
                padding: 20px;
            }

            .btn-group {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <div class="form-header">
        <h1>用户信息表单</h1>
        <p>请填写以下信息完成注册</p>
    </div>

    <div class="form-content">
        <form id="userForm">
            <div id="div1" class="form-group">
                <label for="search">搜索：</label>
                <input type="search" id="search" name="search" placeholder="请输入搜索的内容">
            </div>

            <div class="form-group">
                <label for="username">姓名：</label>
                <input type="text" id="username" name="username" required>
                <div class="error-message" id="username-error">设置获取焦点属性，不能为空</div>
            </div>

            <div class="form-group">
                <label for="password">密码：</label>
                <div class="input-with-feedback">
                    <input type="password" id="password" name="password" required>
                    <div class="feedback-text" id="password-feedback"></div>
                </div>
                <div class="error-message" id="password-error">密码不能为空</div>
            </div>

            <div class="form-group">
                <label for="email">邮箱：</label>
                <input type="email" id="email" name="email" required>
                <div class="error-message" id="email-error">input类型为email，不能为空</div>
            </div>

            <div class="form-group">
                <label for="phone">电话：</label>
                <input type="tel" id="phone" name="phone" required>
                <div class="error-message" id="phone-error">tel，不能为空</div>
            </div>

            <div class="form-group">
                <label for="age">年龄：</label>
                <input type="number" id="age" name="age" min="18" max="99" value="20" required>
                <div class="error-message" id="age-error">number，最小18，最大99，步长1，默认20</div>
            </div>

            <div class="form-group">
                <label for="birthdate">出生日期：</label>
                <input type="date" id="birthdate" name="birthdate" required>
            </div>

            <div class="form-group">
                <label>性别：</label>
                <div class="radio-group">
                    <label class="radio-option">
                        <input type="radio" name="gender" value="女" required> 女
                    </label>
                    <label class="radio-option">
                        <input type="radio" name="gender" value="男"> 男
                    </label>
                </div>
            </div>

            <div class="form-group">
                <label for="joinDate">入职时间：</label>
                <input type="month" id="joinDate" name="joinDate" required>
            </div>

            <div class="form-group">
                <label for="salary">薪资待遇：</label>
                <div class="range-container">
                    <input type="range" id="salary" name="salary" min="1000" max="100000" step="100" value="6500">
                    <div class="range-value" id="salary-value">6500</div>
                </div>
            </div>

            <div class="form-group">
                <label for="submitTime">填表时间：</label>
                <input type="time" id="submitTime" name="submitTime" required>
            </div>

            <div class="form-group">
                <label for="weekInfo">本周是第几周：</label>
                <input type="week" id="weekInfo" name="weekInfo" required>
            </div>

            <div class="form-group">
                <label for="workUrl">作品网址：</label>
                <input type="url" id="workUrl" name="workUrl" placeholder="https://example.com">
            </div>

            <div class="form-group">
                <label for="favoriteColor">请选择喜欢的颜色：</label>
                <div style="display: flex; align-items: center;">
                    <input type="color" id="favoriteColor" name="favoriteColor" value="#4361ee">
                    <span class="color-preview" id="colorPreview" style="background-color: #4361ee;"></span>
                </div>
            </div>

            <div class="btn-group">
                <button type="submit" class="btn btn-primary">提交</button>
                <button type="reset" class="btn btn-secondary">重置</button>
            </div>
        </form>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        // 设置默认值
        const now = new Date();
        document.getElementById('submitTime').value = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`;

        // 薪资范围显示
        const salaryInput = document.getElementById('salary');
        const salaryValue = document.getElementById('salary-value');

        salaryInput.addEventListener('input', function() {
            salaryValue.textContent = this.value;
        });

        // 颜色选择器预览
        const colorInput = document.getElementById('favoriteColor');
        const colorPreview = document.getElementById('colorPreview');

        colorInput.addEventListener('input', function() {
            colorPreview.style.backgroundColor = this.value;
        });

        // 密码输入反馈
        const passwordInput = document.getElementById('password');
        const passwordFeedback = document.getElementById('password-feedback');

        passwordInput.addEventListener('input', function() {
            passwordFeedback.textContent = `您的输入是: ${this.value.replace(/./g, '*')}`;
        });

        // 表单验证
        const userForm = document.getElementById('userForm');

        userForm.addEventListener('submit', function(event) {
            event.preventDefault();

            let isValid = true;

            // 验证姓名
            const username = document.getElementById('username');
            if (!username.value.trim()) {
                document.getElementById('username-error').style.display = 'block';
                isValid = false;
            } else {
                document.getElementById('username-error').style.display = 'none';
            }

            // 验证密码
            const password = document.getElementById('password');
            if (!password.value) {
                document.getElementById('password-error').style.display = 'block';
                isValid = false;
            } else {
                document.getElementById('password-error').style.display = 'none';
            }

            // 验证邮箱
            const email = document.getElementById('email');
            if (!email.value || !email.validity.valid) {
                document.getElementById('email-error').style.display = 'block';
                isValid = false;
            } else {
                document.getElementById('email-error').style.display = 'none';
            }

            // 验证电话
            const phone = document.getElementById('phone');
            if (!phone.value) {
                document.getElementById('phone-error').style.display = 'block';
                isValid = false;
            } else {
                document.getElementById('phone-error').style.display = 'none';
            }

            // 验证年龄
            const age = document.getElementById('age');
            if (!age.value || age.value < 18 || age.value > 99) {
                document.getElementById('age-error').style.display = 'block';
                isValid = false;
            } else {
                document.getElementById('age-error').style.display = 'none';
            }

            if (isValid) {
                alert('表单提交成功！');
                // 这里可以添加表单提交的代码
                // userForm.submit();
            }
        });
    });
</script>
</body>
</html>